<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax应用</title>
    <meta name="referrer" content="no-referrer"/>
    <script src="../js/jquery-3.1.1.min.js"></script>
    <style>
        .div3{
            float: left;
            text-align: center;
        }
        .div4{
            float: left;
            text-align: center;
        }
        img{
            width: 200px;
            height: 300px;
            margin-left: 100px;
        }
    </style>
    <script>
        $(function () {
            function xh(){
                $(".div4").hide();
                $(".div3").show();
                $.ajax({
                    method:"get",
                    url:"https://douban.uieee.com/v2/movie/top250?start=10",
                    dataType:"jsonp",
                    success:function (r) {
                        // let myimg = $("<img src="+r.images.small+">");
                        // $(".div3").append(myimg);
                        for(let i=0;i<=10;i++){
                            let myimgs = $("<img src="+r.subjects[i].images.small+">");
                            let titles = $("<p>"+r.subjects[i].title+"</p>").css({"color":"#0FF"});
                            let rating = $("<p>评分："+r.subjects[i].rating.average+"</p>").css({"color":"red"});
                            let temp = i+1;
                            $(".div3:nth-child("+temp+")").prepend(myimgs).append(titles).append(rating);
                        }
                    }



            });
                       }

            function gf(){
                $(".div3").hide();
                $(".div4").show();
                $.ajax({
                    method:"get",
                    url:"https://douban.uieee.com/v2/movie/top250?start=20",
                    dataType:"jsonp",
                    success:function (r) {
                        for(let i=0;i<=10;i++){
                            let myimgs = $("<img src="+r.subjects[i].images.small+">");
                            let titles = $("<p>"+r.subjects[i].title+"</p>").css({"color":"#0FF"});
                            let rating = $("<p>评分："+r.subjects[i].rating.average+"</p>").css({"color":"#0FF"});
                            let temp = i+1;
                            $(".div4:nth-child("+temp+")").prepend(myimgs).append(titles).append(rating);
                        }
                    }
                });

        }

        $("#btn3").click(function () {
            xh();
        })
        $("#btn4").click(function () {
            gf();
        })
        xh();
        });



    </script>
</head>
<body>
<div>
    <input id="btn3" type="button" value="我喜欢的电影"/>
    <input id="btn4" type="button" value="高评分电影"/>
</div>
<div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
    <div class="div3"></div>
</div>
<div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
    <div class="div4"></div>
</div>















</body>
</html>